//
//  VideoPlayView.m
//  OnionHome
//
//  Created by fengjie on 2019/10/8.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "VideoPlayView.h"
//#import "CLPlayerView.h"
#import "FJPlayerView.h"

//间隙
#define Padding        10


@interface VideoPlayView ()
/**<#属性#>*/
@property (nonatomic,strong)FJPlayerView*playerView;

@end

@implementation VideoPlayView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
-(void)setModel:(VideoPlayModel *)model{
    _model = model;
    //销毁播放器
    [self.playerView destroyPlayer];
    
    FJPlayerView *playerView = [[FJPlayerView alloc] initWithFrame:CGRectZero];
    self.playerView = playerView;
    [self addSubview:self.playerView];
    [playerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    //重复播放，默认不播放
//    _playerView.repeatPlay = YES;
    //设置进度条背景颜色
    _playerView.progressBackgroundColor = [UIColor colorWithRed:53 / 255.0 green:53 / 255.0 blue:65 / 255.0 alpha:1];
    //设置进度条缓冲颜色
    _playerView.progressBufferColor = [UIColor grayColor];
    //设置进度条播放完成颜色
    _playerView.progressPlayFinishColor = UIColorFromRGB(0x009966);
    //视频地址
    _playerView.url = model.url;
    //播放
    [_playerView playVideo];
    //返回按钮点击事件回调
    [_playerView destroyPlay:^{
        DLog(@"播放器被销毁了");
    }];
    [_playerView backButton:^(UIButton *button) {
        DLog(@"返回按钮被点击");
    }];
    //播放完成回调
//    kWeakSelf(weakSelf);
    [_playerView endPlay:^{
        //销毁播放器
//        [weakSelf.playerView destroyPlayer];
//        weakSelf.playerView = nil;
//        weakSelf.cell = nil;
        DLog(@"播放完成");
    }];

}
/**暂停*/
- (void)pausePlay{
    [self.playerView pausePlay];
}

/**播放*/
- (void)playVideo{
    [self.playerView playVideo];
}
#pragma mark - 销毁播放器
- (void)destroyPlayer{
    [self.playerView destroyPlayer];
}
@end
